﻿using System;
using System.Collections.Generic;
using System.Text;
using SharpDiary.Core.Data;
using SharpDiary.Core.Utility;

namespace SharpDiary.Core.ORMapping
{
    [TableInfoAttribute("MemoInfo")]
    public class MemoInfo : DbMappingObjectBase
    {
        #region Fields & Properties

        private Int64 _id = -1;

        /// <summary>
        /// 编号。
        /// </summary>
        [FieldMapping(true, System.Data.DbType.Int64, true, true)]
        public Int64 Id
        {
            get { return _id; }
            set { _id = value; }
        }

        private string _content = string.Empty;

        /// <summary>
        /// 内容。
        /// </summary>
        [FieldMapping(false, System.Data.DbType.Int64, false, false)]
        public string Content
        {
            get { return _content; }
            set { _content = value; }
        }


        #endregion

        #region Constructors

        public MemoInfo() { }

        #endregion

        #region Methods

        /// <summary>
        /// 判断指定内容是否已存在。
        /// </summary>
        /// <param name="content">格言内容</param>
        /// <returns>否已存在</returns>
        public static bool Exists(string content)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendLine("select * from MemoInfo where Content = @content");

            DataAccessService das = Utils.GetDataAccessServiceInstance();

            object result = das.ExecuteScalar(sql.ToString(), System.Data.CommandType.Text,
                das.CreateParameter("@content", System.Data.DbType.String, content));
            return (result != null && result != DBNull.Value ? Convert.ToInt32(result) > 0 : false);
        }

        #endregion

    }
}
